package com.my.client.handler;


import com.google.gwt.user.client.rpc.AsyncCallback;
import com.my.client.GreetingServiceAsync;
import com.my.client.util.FormMap;
import com.my.client.util.ResultMap;
import com.my.client.util.StaticService;
import com.my.client.util.UIRender;

public abstract class  MyHandler implements AsyncCallback<String>{
	protected FormMap formMap;
	protected ResultMap resultMap;
	protected UIRender ur ;

	public void onFailure(Throwable caught) {
		// TODO Auto-generated method stub
		caught.printStackTrace();
    }
    
	public void onSuccess(String result) {
		// TODO Auto-generated method stub
		if(result == null) ur.render(null);
		else{
		resultMap = new ResultMap();	
		processResult(result,resultMap);
		if(resultMap==null){
			System.err.print("result map is null");
		}
		ur.render(resultMap);
		}
	}
	
	public void handler(){
		handler(formMap);
	}
	public abstract void handler(FormMap formMap) ;
	public GreetingServiceAsync getService(){
		return StaticService.getInstance().getService();
	}
	public  abstract void processResult(String result, ResultMap resultMap);

	public void setUIRender(UIRender ur) {
		// TODO Auto-generated method stub
		this.ur = ur;
		
	}

	public void setFormap(FormMap formMap) {
		// TODO Auto-generated method stub
		this.formMap = formMap;
	}
}